<template>
  <div class="self_adaption">
    <div class="other">
      <p class="main_text">估价管理</p>
    </div>
    <div class="table">
      <button class="solid" style="margin: 20px 1% 0" @click="addPriceBtn">添加价格</button>
      <button class="hollow" style="margin: 20px 1% 0" @click="exportExcelList">数据导出</button>
      <button class="del_btn" style="margin: 20px 1% 0" @click="delList">批量删除</button>
      <el-table
        :data="tableData"
        :span-method="objectSpanMethod"
        ref="tableRef"
        border
        style="width: 100%"
        @select-all="handleSelectionChange"
        @select="handleSelectionChange">
        <el-table-column type="selection" width="40" />
        <el-table-column prop="carType" label="类别" align="center" width="180">
          <template #default="item">
            <span v-show="!show">{{ item.row.carType }}</span>
            <el-select v-model="item.row.carType" class="m-2" filterable v-show="show" placeholder="请选择标准类别态">
              <el-option
                v-for="item in carType_options"
                :key="item.carType"
                :label="item.carType"
                :value="item.carType">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column prop="nickName" label="通俗类别" align="center" width="180">
          <template #default="item">
            <span v-if="!show && item.row.nickName">{{ item.row.nickName }}</span>
            <span v-else-if="!show && !item.row.nickName">--</span>
            <el-input v-else v-model="item.row.nickName" placeholder="请输入通俗类型" />
          </template>
        </el-table-column>
        <el-table-column label="吨位区间" align="center" v-if="!show" width="120">
          <template #default="item"> {{ item.row.carWeightMin }} - {{ item.row.carWeightMax }} </template>
        </el-table-column>
        <el-table-column label="最低吨位(包含)" align="center" v-if="show" width="180">
          <template #default="item">
            <el-input-number
              v-model="item.row.carWeightMin"
              :min="0"
              :max="item.row.carWeightMax"
              :precision="2"
              :step="1" />
          </template>
        </el-table-column>
        <el-table-column label="最高吨位(不包含)" align="center" v-if="show" width="180">
          <template #default="item">
            <el-input-number
              v-model="item.row.carWeightMax"
              :min="item.row.carWeightMin"
              :max="100"
              :precision="2"
              :step="1" />
          </template>
        </el-table-column>
        <el-table-column label="轮毂类型" align="center" width="140">
          <template #default="item">
            <span v-show="!show && item.row.hubType">{{ item.row.hubType }}</span>
            <span v-show="!show && !item.row.hubType">--</span>
            <el-select v-model="item.row.hubType" class="m-2" v-show="show" placeholder="请选择轮毂类型">
              <el-option v-for="item in hubType_options" :key="item.label" :label="item.label" :value="item.label">
              </el-option>
            </el-select>
          </template>
        </el-table-column>
        <el-table-column label="扣杂系数 %" align="center" width="200">
          <template #default="item">
            <span v-show="!show">{{ item.row.deductRatio }}%</span>
            <el-input-number
              v-model="item.row.deductRatio"
              :min="0"
              :max="100"
              v-show="show"
              :precision="0"
              :step="1" />
          </template>
        </el-table-column>
        <el-table-column label="三元催化(元)" align="center" width="180">
          <template #default="item">
            <span v-if="!show">{{ item.row.sanYuanPrice }}</span>
            <el-input-number v-else v-model="item.row.sanYuanPrice" :min="0" :max="1000" :precision="2" :step="1" />
          </template>
        </el-table-column>
        <el-table-column prop="price" label="到厂价(元)" align="center" v-if="!show" width="120" />
        <el-table-column label="到厂价(元)" align="center" v-else width="180">
          <template #default="item">
            <el-input-number v-model="item.row.newPrice" :min="1" :max="100000" :precision="2" :step="1" />
          </template>
        </el-table-column>
        <el-table-column label="业务员收车价(元)" prop="salesmanPrice" align="center" width="180">
          <template #default="item">
            <span v-if="!show">{{ item.row.salesmanPrice }}</span>
            <el-input-number v-else v-model="item.row.salesmanPrice" :min="0" :max="100000" :precision="2" :step="1" />
          </template>
        </el-table-column>
        <el-table-column label="运补(元)" prop="transSubsidy" align="center" width="180">
          <template #default="item">
            <span v-if="!show">{{ item.row.transSubsidy }}</span>
            <el-input-number v-else v-model="item.row.transSubsidy" :min="0" :max="100000" :precision="2" :step="1" />
          </template>
        </el-table-column>
        <el-table-column label="是否过磅" align="center" width="100">
          <template #default="item">
            <el-switch v-model="item.row.fNeedWeigh" :disabled="!show" />
          </template>
        </el-table-column>
        <el-table-column label="是否启用" align="center" width="100">
          <template #default="item">
            <el-switch v-model="item.row.enable" :disabled="!show" />
          </template>
        </el-table-column>
        <el-table-column prop="note" label="备注" align="center" width="200">
          <template #default="item">
            <span v-if="!show && item.row.note !== null">{{ item.row.note }}</span>
            <span v-else-if="!show && item.row.note == null">-</span>
            <div v-else>
              <el-input v-model="item.row.note" rows="3" type="textarea" :disabled="!show" />
            </div>
          </template>
        </el-table-column>
        <el-table-column fixed="right" label="操作" prop="operation" width="180" colspan="5" align="center">
          <template #default="item">
            <el-button class="none" v-show="!show" @click="EditPtice" v-if="roleList.write">修改定价</el-button>
            <div style="display: flex; align-items: center; justify-content: space-between" v-show="show">
              <el-button class="none" @click="submit"
                ><el-tooltip
                  class="box-item"
                  effect="dark"
                  content="价格设定一旦完成，会自动进入车辆回收价格匹配参数，请确保您的价格设定符合合理的市场价区间，以便提升您的回收效益"
                  placement="bottom">
                  <el-icon>
                    <Warning />
                  </el-icon> </el-tooltip
                >提交审核</el-button
              >
              <el-button class="none" @click="deliverCancel" style="margin-left: 0">取消</el-button>
            </div>
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div id="mask1" v-show="mask" @click="maskBtn1"></div>
    <!-- /////////////////////////////////////////////////////////////////        提交审核弹框        ////////////////////////////////////////////////////////// -->
    <div class="audit" v-show="audit">
      <div class="title1">
        <div class="title_mes">
          <el-icon size="20" color="#fff"> <Edit /> </el-icon>&nbsp;是否确认提交估价审核
        </div>
        <span class="close" @click="maskBtn1">✖</span>
      </div>
      <div class="content1">
        <div class="mes_title" style="margin-top: 40px; margin-bottom: 10px; color: #7e7e7e; font-size: 12px">
          请填写调价原因
        </div>
        <el-input placeholder="请输入" v-model="reason" style="margin-bottom: 15px"></el-input>
        <text style="font-size: 14px; color: #606266"
          >*价格设定一旦完成，会自动进入车辆回收价格匹配参数，请确保您的价格设定符合合理的市场价区间，以便提升您的回收效益。</text
        >
        <!-- 按钮区域 -->
        <div class="btn_center">
          <el-button class="hollow" @click="deliverCancel">取消</el-button>
          <el-button class="solid" @click="deliverSure">确定</el-button>
        </div>
      </div>
    </div>
    <!-- /////////////////////////////////////////////////////////////////        添加价格弹框        ////////////////////////////////////////////////////////// -->
    <div class="addPrice" v-show="addPrice">
      <div class="title1" style="position: sticky; z-index: 99; top: 0">
        <div class="title_mes">
          <el-icon size="20" color="#fff"> <Edit /> </el-icon>&nbsp;添加估价
        </div>
        <span class="close" @click="maskBtn1">✖</span>
      </div>
      <div class="content1">
        <el-form ref="ruleFormRef" :model="GoodsformDate" label-width="120px" label-position="right" :rules="rules">
          <div style="width: 80%; padding: 20px 10%"></div>
          <el-form-item label="标准类别:" prop="carType">
            <el-select v-model="GoodsformDate.carType" class="m-2" filterable placeholder="请选择标准类别态">
              <el-option
                v-for="item in carType_options"
                :key="item.carType"
                :label="item.carType"
                :value="item.carType">
              </el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="通俗类别:" prop="nickName">
            <el-input v-model="GoodsformDate.nickName" placeholder="请输入通俗类别" />
          </el-form-item>
          <el-form-item label="轮毂类型:" prop="hubType">
            <el-radio-group v-model="GoodsformDate.hubType">
              <el-radio label="铝轮毂" size="large">铝轮毂</el-radio>
              <el-radio label="铁轮毂" size="large">铁轮毂</el-radio>
            </el-radio-group>
          </el-form-item>
          <el-form-item label="吨位区间:" prop="carWeightMin">
            <el-input-number v-model="GoodsformDate.carWeightMin" :min="0" :max="1000" />
            &emsp;至&emsp;
            <el-input-number v-model="GoodsformDate.carWeightMax" :min="0" :max="1000" />
          </el-form-item>
          <el-form-item label="扣杂系数 %:" prop="deductRatio">
            <el-input-number v-model="GoodsformDate.deductRatio" :min="0" :max="100" :precision="0" :step="1" />
          </el-form-item>
          <el-form-item label="回收价格:" prop="price">
            <el-input v-model="GoodsformDate.price" placeholder="请输入价格" type="number">
              <template #prepend>￥</template>
            </el-input>
          </el-form-item>
          <el-form-item label="业务员收车价:" prop="salesmanPrice">
            <el-input v-model="GoodsformDate.salesmanPrice" placeholder="请输入价格" type="number">
              <template #prepend>￥</template>
            </el-input>
          </el-form-item>
          <el-form-item label="运补:" prop="transSubsidy">
            <el-input v-model="GoodsformDate.transSubsidy" placeholder="请输入价格" type="number">
              <template #prepend>￥</template>
            </el-input>
          </el-form-item>
          <el-form-item label="三元催化定价:" prop="sanYuanPrice" type="number">
            <el-input v-model="GoodsformDate.sanYuanPrice" placeholder="请输入三元催化定价">
              <template #prepend>￥</template>
            </el-input>
          </el-form-item>
          <el-form-item label="说明:" prop="note">
            <el-input
              v-model="GoodsformDate.note"
              cols="30"
              rows="4"
              class="form_input"
              type="textarea"
              maxlength="300"
              show-word-limit></el-input>
          </el-form-item>
          <el-form-item label="是否过磅:" prop="enable" :required="true">
            <el-switch v-model="GoodsformDate.fNeedWeigh" />
          </el-form-item>
          <el-form-item label="是否启用:" prop="enable" :required="true">
            <el-switch v-model="GoodsformDate.enable" />
          </el-form-item>
        </el-form>
      </div>
      <!-- 按钮区域 -->
      <div style="float: right; margin: 32px">
        <el-button class="hollow" @click="maskBtn1">取消</el-button>
        <el-button class="solid" @click="addSure(ruleFormRef)">确定</el-button>
      </div>
    </div>
    <!-- /////////////////////////////////////////////////////////////////        添加价格弹框        ////////////////////////////////////////////////////////// -->
    <div class="addPrice addPrice1" v-show="firstAddPrice">
      <div class="title1" style="position: sticky; z-index: 99; top: 0">
        <div class="title_mes">
          <el-icon size="20" color="#fff"> <Edit /> </el-icon>&nbsp;添加估价1
        </div>
        <span class="close" @click="maskBtn1">✖</span>
      </div>
      <div class="content1">
        <el-table :data="newList" border style="width: 100%">
          <el-table-column prop="carType" label="类别" align="center" width="180">
            <template #default="item">
              {{ item.row.carType }}
              <!-- <el-select v-model="item.row.carType" class="m-2" filterable placeholder="请选择标准类别态">
                <el-option
                  v-for="item in carType_options"
                  :key="item.carType"
                  :label="item.carType"
                  :value="item.carType">
                </el-option>
              </el-select> -->
            </template>
          </el-table-column>
          <el-table-column prop="nickName" label="通俗类别" align="center" width="180">
            <template #default="item">
              <el-input v-model="item.row.nickName" placeholder="请输入通俗类型" />
            </template>
          </el-table-column>
          <el-table-column label="最低吨位(包含)" align="center" width="180">
            <template #default="item">
              <el-input-number v-model="item.row.carWeightMin" :min="0" :max="100" :precision="2" :step="1" />
            </template>
          </el-table-column>
          <el-table-column label="最高吨位(不包含)" align="center" width="180">
            <template #default="item">
              <el-input-number v-model="item.row.carWeightMax" :min="0" :max="100" :precision="2" :step="1" />
            </template>
          </el-table-column>
          <el-table-column label="轮毂类型" align="center" width="140">
            <template #default="item">
              <el-select v-model="item.row.hubType" class="m-2" placeholder="请选择轮毂类型">
                <el-option v-for="item in hubType_options" :key="item.label" :label="item.label" :value="item.label">
                </el-option>
              </el-select>
            </template>
          </el-table-column>
          <el-table-column label="扣杂系数 %" align="center" width="200">
            <template #default="item">
              <el-input-number v-model="item.row.deductRatio" :min="0" :max="100" :precision="0" :step="1" />
            </template>
          </el-table-column>
          <el-table-column label="三元催化(元)" align="center" width="180">
            <template #default="item">
              <el-input-number v-model="item.row.sanYuanPrice" :min="0" :max="1000" :precision="2" :step="1" />
            </template>
          </el-table-column>
          <el-table-column label="到厂价(元)" align="center" width="180">
            <template #default="item">
              <el-input-number v-model="item.row.price" :min="1" :max="100000" :precision="2" :step="1" />
            </template>
          </el-table-column>
          <el-table-column label="业务员回收价(元)" align="center" width="180">
            <template #default="item">
              <el-input-number v-model="item.row.salesmanPrice" :min="0" :max="100000" :precision="2" :step="1" />
            </template>
          </el-table-column>
          <el-table-column label="运补(元)" align="center" width="180">
            <template #default="item">
              <el-input-number v-model="item.row.transSubsidy" :min="0" :max="100000" :precision="2" :step="1" />
            </template>
          </el-table-column>
          <el-table-column label="是否启用" align="center" width="100">
            <template #default="item">
              <el-switch v-model="item.row.enable" />
            </template>
          </el-table-column>
          <el-table-column prop="note" label="备注" align="center" width="200">
            <template #default="item">
              <el-input v-model="item.row.note" rows="3" type="textarea" />
            </template>
          </el-table-column>
        </el-table>
      </div>
      <!-- 按钮区域 -->
      <div style="float: right; margin: 32px">
        <el-button class="hollow" @click="maskBtn1">取消</el-button>
        <el-button class="solid" @click="firstAddSure(ruleFormRef)">确定</el-button>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
import {ref, onMounted, reactive, nextTick, getCurrentInstance} from 'vue';
import {
  RequestShopValuation,
  RequestShopValuationSetting,
  RequestauditPriceApplyAudit,
  RequestCollectionPriceCarType,
  RequestCollectionPriceSave,
  RequestCollectionPriceDeleteList,
} from '@/api/path/index.js';
import {ElMessage, ElInput, FormInstance} from 'element-plus';
import {Warning, Edit} from '@element-plus/icons-vue';
import moment from 'moment';
import useAuthorize from '@/hooks/authorize';
let roleList = useAuthorize();
const tableData = ref<any>([]); //表格数据
const show = ref(false); //标示是否正在修改
const mask = ref(false); //控制弹框，遮罩层的显示
const node = JSON.parse(localStorage.getItem('roleInfo')!).company; //厂家id
const effectTime = ref(); //设置更新时间
const tableRef = ref();
const {ctx} = getCurrentInstance();
onMounted(() => {
  requestShopValuation();
  requestCollectionPriceCarType();
  setTimeout(() => {
    ctx.$refs.tableRef.doLayout();
  }, 2000);
});
const delIds = ref('');
const handleSelectionChange = (selection: any) => {
  delIds.value = '';
  console.log('选择', selection);
  selection.forEach((item: any) => {
    if (delIds.value == '') {
      delIds.value = item.id;
    } else {
      delIds.value = delIds.value + ',' + item.id;
    }
  });
  console.log('删除', delIds.value);
};
const delList = async () => {
  const a = await RequestCollectionPriceDeleteList(delIds.value);
  if (a.msg == '操作成功！') {
    ElMessage.success('操作成功！');
    requestShopValuation();
  }
};
const newList = ref<any>([]);
const newList1 = ref(['微型轿车', '小型轿车', '小型面包车', '小型普通客车']);
const requestShopValuation = async () => {
  tableData.value = [];
  const a = await RequestShopValuation(node);
  for (let i = 0; i < a.resultObj.length; i++) {
    tableData.value = tableData.value.concat(a.resultObj[i]);
  }
  tableData.value.forEach((item: any) => {
    item.newPrice = item.price;
    item.deductRatio = item.deductRatio * 100;
  });
  if (tableData.value.length == 0) {
    newList.value = [];
    newList1.value.forEach((item, index) => {
      newList.value.push({
        carType: item,
        nickName: '',
        hubType: '铝轮毂',
        carWeightMin: '',
        carWeightMax: '',
        deductRatio: '',
        price: 100,
        salesmanPrice: 0,
        transSubsidy: 0,
        sanYuanPrice: '',
        note: '',
        fNeedWeigh: false,
        enable: true,
        companyNode: node,
      });
    });
  }
  console.log('获取成功', newList.value);
};
const carType_options = ref<any>([]); //车辆类型
const requestCollectionPriceCarType = async () => {
  const a = await RequestCollectionPriceCarType();
  carType_options.value = a.resultObj;
};
const objectSpanMethod = ({
  row,
  column,
  rowIndex,
  columnIndex,
}: {
  row: any;
  column: any;
  rowIndex: number;
  columnIndex: number;
}) => {
  if (show.value) {
    if (columnIndex === 14) {
      return {
        rowspan: tableData.value.length, // 可以根据需要调整行数
        colspan: 1, // 合并当前行的所有列
      };
    }
  } else {
    if (columnIndex === 13) {
      return {
        rowspan: tableData.value.length, // 可以根据需要调整行数
        colspan: 1, // 合并当前行的所有列
      };
    }
  }
};
// 引入导出Excel表格依赖
import * as XLSX from 'xlsx';
/**
 * 导出信息
 */
const exportBox = ref([]);
const exportExcelList = async () => {
  console.log('数据导出', tableData.value);
  exportBox.value = JSON.parse(JSON.stringify(tableData.value));
  exportBox.value.forEach((item: any) => {
    item.newPrice = item.price;
    item.deductRatio = item.deductRatio + '%';
  });
  const titleArr = ['编号', '吨位区间', '车辆类型', '轮毂类型', '扣杂系数', '当前回收价格']; //表头中文名
  exportExcel(exportBox.value, titleArr, 'sheetName');
};
function exportExcel(list: any, titleArr: any, sheetName: any) {
  /* convert state to workbook */
  var data = new Array();
  var keyArray = new Array();
  const getLength = function (obj) {
    var count = 0;
    for (var i in obj) {
      if (obj.hasOwnProperty(i)) {
        count++;
      }
    }
    return count;
  };
  // 获取数组的length
  for (const key1 in list) {
    if (list.hasOwnProperty(key1)) {
      const element = list[key1];
      var rowDataArray = new Array();
      // 获取每一层里面有多少数据
      rowDataArray[0] = element['id'];
      rowDataArray[1] = element['carWeightMin'] + '-' + element['carWeightMax'];
      rowDataArray[2] = element['carType'];
      rowDataArray[3] = element['hubType'];
      rowDataArray[4] = element['deductRatio'];
      rowDataArray[5] = element['price'];
      for (const key2 in element) {
        if (keyArray.length < getLength(element)) {
          keyArray.push(key2);
        }
      }
      data.push(rowDataArray);
    }
  }
  // keyArray为英文字段表头
  data.splice(0, 0, keyArray, titleArr);
  console.log('data', data);
  const ws = XLSX.utils.aoa_to_sheet(data);
  const wb = XLSX.utils.book_new();
  // 此处隐藏英文字段表头
  var wsrows = [{hidden: true}];
  ws['!rows'] = wsrows; // ws - worksheet
  XLSX.utils.book_append_sheet(wb, ws, sheetName);
  /* generate file and send to client */
  XLSX.writeFile(wb, moment(new Date()).format('yyyy-MM-DD HH/mm/ss') + '所有整车估价管理.xlsx');
}
const hubType_options = ref([
  {
    label: '铁轮毂',
    value: '铁轮毂',
  },
  {
    label: '铝轮毂',
    value: '铝轮毂',
  },
]);
/**
 * 添加价格
 */
const addPrice = ref(false);
const firstAddPrice = ref(false);
const addPriceBtn = () => {
  if (tableData.value.length) {
    addPrice.value = true;
    mask.value = true;
    GoodsformDate.value = {
      carType: '',
      nickName: '',
      hubType: '铝轮毂',
      deductRatio: 0,
      carWeightMin: 0,
      carWeightMax: 0,
      price: '',
      transSubsidy: '',
      salesmanPrice: '',
      sanYuanPrice: '',
      note: '',
      fNeedWeigh: false,
      enable: true,
      companyNode: node,
    };
  } else {
    firstAddPrice.value = true;
    mask.value = true;
  }
};
const GoodsformDate = ref({
  carType: '',
  nickName: '',
  hubType: '铝轮毂',
  deductRatio: 0,
  carWeightMin: 0,
  carWeightMax: 0,
  price: '',
  transSubsidy: '',
  salesmanPrice: '',
  sanYuanPrice: '',
  note: '',
  fNeedWeigh: false,
  enable: true,
  companyNode: node,
});
const ruleFormRef = ref<FormInstance>();
// 表单规则
const rules = reactive({
  carType: [{required: true, message: '请选择车辆类型', trigger: 'blur'}],
  hubType: [{required: true, message: '请选择轮毂类型', trigger: 'blur'}],
  carWeightMin: [
    {required: true, message: '请输入最低吨位', trigger: 'blur'},
    {
      pattern: /^(([1-9]{1}\d*)|(0{1}))(\.\d{1,2})?$/,
      message: '请输入正确的吨位',
      trigger: 'blur',
    },
  ],
  carWeightMax: [
    {required: true, message: '请输入最高吨位', trigger: 'blur'},
    {
      pattern: /^(([1-9]{1}\d*)|(0{1}))(\.\d{1,2})?$/,
      message: '请输入正确的吨位',
      trigger: 'blur',
    },
  ],
  price: [
    {required: true, message: '请输入回收价格', trigger: 'blur'},
    {
      pattern: /^(([1-9]{1}\d*)|(0{1}))(\.\d{1,2})?$/,
      message: '请输入合法的金额数字，最多两位小数',
      trigger: 'blur',
    },
    {
      validator: (rule: any, value: any, callback: any) => {
        if (value < 0 || value > 100000) {
          callback(new Error('价格须在0~100000之间'));
        } else {
          callback();
        }
      },
      trigger: 'blur',
    },
  ],
  salesmanPrice: [
    {required: false, message: '请输入回收员业务价', trigger: 'blur'},
    {
      pattern: /^(([1-9]{1}\d*)|(0{1}))(\.\d{1,2})?$/,
      message: '请输入合法的金额数字，最多两位小数',
      trigger: 'blur',
    },
    {
      validator: (rule: any, value: any, callback: any) => {
        if (value < 0 || value > 100000) {
          callback(new Error('价格须在0~100000之间'));
        } else {
          callback();
        }
      },
      trigger: 'blur',
    },
  ],
  transSubsidy: [
    {required: false, message: '请输入运补', trigger: 'blur'},
    {
      pattern: /^(([1-9]{1}\d*)|(0{1}))(\.\d{1,2})?$/,
      message: '请输入合法的金额数字，最多两位小数',
      trigger: 'blur',
    },
    {
      validator: (rule: any, value: any, callback: any) => {
        if (value < 0 || value > 100000) {
          callback(new Error('价格须在0~100000之间'));
        } else {
          callback();
        }
      },
      trigger: 'blur',
    },
  ],
  sanYuanPrice: [
    {required: true, message: '请输入三元催化定价', trigger: 'blur'},
    {
      pattern: /^(([1-9]{1}\d*)|(0{1}))(\.\d{1,2})?$/,
      message: '请输入合法的金额数字，最多两位小数',
      trigger: 'blur',
    },
    {
      validator: (rule: any, value: any, callback: any) => {
        if (value < 0 || value > 1000) {
          callback(new Error('价格须在0~1000之间'));
        } else {
          callback();
        }
      },
      trigger: 'blur',
    },
  ],
  deductRatio: [{required: true, message: '请输入扣杂率', trigger: 'blur'}],
});
const sendMes = ref();
const addSure = async (formEl: any) => {
  if (!formEl) return;
  await formEl.validate(async (valid: any, fields: any) => {
    if (valid) {
      if (GoodsformDate.value.carWeightMin > GoodsformDate.value.carWeightMax) {
        ElMessage.error('最低吨位不能高于最高吨位');
      } else {
        console.log(GoodsformDate.value);
        sendMes.value = JSON.parse(JSON.stringify(GoodsformDate.value));
        sendMes.value.deductRatio = Number(sendMes.value.deductRatio / 100).toFixed(2);
        const a = await RequestCollectionPriceSave(sendMes.value);
        if (a.msg == '操作成功！') {
          ElMessage.success('添加成功！');
          mask.value = false;
          addPrice.value = false;
          requestShopValuation();
        }
      }
    } else {
      ElMessage.error('请先完成所有信息！');
    }
  });
};
/**
 * 点击提交
 */
const audit = ref(false);
const submit = () => {
  console.log(123);
  mask.value = true;
  audit.value = true;
};
const isTrue = ref(true);
const firstAddSure = async (formEl: any) => {
  isTrue.value = true;
  for (let i = 0; i < newList.value.length; i++) {
    if (newList.value[i].carWeightMin >= newList.value[i].carWeightMax) {
      ElMessage.error('最低吨位不能大于等于最高吨位');
      isTrue.value = false;
      return;
    }
  }
  if (isTrue.value) {
    for (let i = 0; i < newList.value.length; i++) {
      sendMes.value = JSON.parse(JSON.stringify(newList.value[i]));
      sendMes.value.deductRatio = Number(sendMes.value.deductRatio / 100).toFixed(2);
      await RequestCollectionPriceSave(sendMes.value);
    }
    firstAddPrice.value = false;
    mask.value = false;
    requestShopValuation();
  }
};
/**
 * 遮罩层
 */
const maskBtn1 = () => {
  mask.value = false;
  audit.value = false;
  addPrice.value = false;
  firstAddPrice.value = false;
};
/**
 * 点击取消修改
 */
const deliverCancel = () => {
  requestShopValuation();
  show.value = !show.value;
  mask.value = false;
  audit.value = false;
};
/**
 * 点击修改定价
 */
const EditPtice = () => {
  var now = new Date();
  now.setHours(0);
  now.setMinutes(0);
  now.setSeconds(0);
  effectTime.value = moment(now).format('yyyy-MM-DD HH:mm:ss');
  show.value = !show.value;
};
/**
 * 确认修改
 */
const reason = ref('');
const deliverSure = async () => {
  console.log('zzzzzzzzzzzzzzzzz4444444444444444444449999999999', tableData.value);

  mask.value = false;
  audit.value = false;
  tableData.value.forEach((item: any) => {
    item.deductRatio = Number(item.deductRatio / 100).toFixed(2);
  });
  const mes = {
    histories: tableData.value,
    reason: reason.value,
    effectTime: effectTime.value,
  };
  const a = await RequestShopValuationSetting(mes);
  console.log('123458', a);
  if (a.msg == '操作成功！') {
    // result0拒绝，1同意
    const result = await RequestauditPriceApplyAudit({
      applyId: a.resultObj,
      result: 1,
      companyNode: JSON.parse(localStorage.getItem('roleInfo')).company,
    });
    if (result.msg == '操作成功！') {
      ElMessage.success('修改成功');
      effectTime.value = '';
      show.value = false;
      reason.value = '';
      tableData.value = [];
      requestShopValuation();
    }
  }
};
</script>

<style lang="scss" scoped>
.table {
  width: 98%;
  height: calc(98% - 70px);
  margin: 1% auto;
  background: #fff;
  overflow: scroll;
}

.el-table {
  margin: 20px auto;
  width: 98% !important;
}

.el-tooltip__popper {
  max-width: 400px !important; //宽度可根据自己需要进行设置
}

/*********************************************      审核弹框样式      ********************************************************/

.audit {
  width: 400px;
  height: 300px;
  background: #fff;
  position: absolute;
  top: 25%;
  left: 30%;
  z-index: 99;

  .btn_center {
    position: absolute;
    bottom: 15px;
    right: 15px;
  }
}

/*********************************************      添加价格弹框样式      ********************************************************/

.addPrice::-webkit-scrollbar {
  display: none;
}
.addPrice {
  width: 60%;
  height: 80%;
  background: #fff;
  position: absolute;
  top: 10%;
  left: 20%;
  z-index: 99;
  overflow: scroll;

  .btn_center {
    position: absolute;
    bottom: 15px;
    right: 15px;
  }
}
.addPrice1 {
  width: 90%;
  left: 5%;
}

#mask1 {
  width: 100vw;
  height: 100vh;
  z-index: 50;
  background: rgb(116, 116, 116, 0.5);
  position: fixed;
  top: 0;
  left: 0;
}

::v-deep .el-input.is-disabled .el-input__wrapper {
  width: 100% !important;
  padding: 0 !important;
}

::v-deep .el-input__prefix {
  margin-left: 20px;
}
::v-deep .el-table--border th.gutter:last-of-type {
  display: block !important;
  width: 17px !important;
}
::v-deep .el-table .cell {
  padding: 0 !important;
}
::v-deep .el-table td.el-table__cell,
.el-table th.el-table__cell.is-leaf {
  padding: 12px;
}
::v-deep .el-table-column--selection {
  padding: 12px;
}
</style>
